<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>捡漏订单列表</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="/static/layuiadmin/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="/static/layuiadmin/style/admin.css" media="all">
</head>
<body>

<style>
    .layui-table-cell{  /*最后的pic为字段的field*/
        height: 100%;
        max-width: 100%;
    }
</style>

<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-header">捡漏订单列表</div>
                <div class="layui-card-body">


                    <div class="layui-form-item layui-form">

                        {if !empty($res)}
                        <div class="layui-inline">
                            <label class="layui-form-label">订单编号</label>
                            <div class="layui-input-block">
                                <select name="order_sn" lay-verify="" lay-search id="order_sn">
                                    <option value="">请选择</option>
                                    {foreach $res as $k=>$v}
                                    <option value="{$v['order_sn']}">{$v['order_sn']}</option>
                                    {/foreach}
                                </select>
                            </div>
                        </div>
                        {/if}

                        {if !empty($date)}
                        <div class="layui-inline">
                            <label class="layui-form-label">期数</label>
                            <div class="layui-input-block">
                                <select name="date" lay-verify="" lay-search id="date">
                                    <option value="">请选择</option>
                                    {foreach $date as $k=>$v}
                                    <option value="{$v['date']}">{$v['date']}</option>
                                    {/foreach}
                                </select>
                            </div>
                        </div>
                        {/if}
                        <div class="layui-inline">
                            <label class="layui-form-label">是否支付</label>
                            <div class="layui-input-block">
                                <select name="order_status" lay-filter="aihao" id="order_status">
                                    <option value=""></option>
                                    <option value="0">未支付</option>
                                    <option value="1">已支付</option>

                                </select>
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">开奖状态</label>
                            <div class="layui-input-block">
                                <select name="is_kaijiang" lay-filter="aihao" id="is_kaijiang">
                                    <option value=""></option>
                                    <option value="0">未到时间</option>
                                    <option value="1">等待开奖</option>
                                    <option value="2">已开奖</option>
                                    <option value="3">人数不足</option>
                                </select>
                            </div>
                        </div>
                        <div class="layui-inline">
                            <div class="layui-btn-group test-table-operate-btn">
                                <button class="layui-btn" data-type="searchUserButton">
                                    <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
                                </button>
                            </div>
                        </div>
                    </div>

                    <table class="layui-hide" id="test-table-operate" lay-filter="test-table-operate" lay-size="lg">

                        <script type="text/html" id="is_use_switch">
                            <input type="checkbox" name="is_display" lay-skin="switch" lay-text="上架|下架" lay-filter="is_use_switch" value="{{ d.is_display }}" data-json="{{ encodeURIComponent(JSON.stringify(d)) }}" {{ d.is_display == 1 ? 'checked' : '' }}>
                        </script>

                    </table>

                    <script type="text/html" id="test-table-operate-barDemo">
                        {{# if(d.order_status==0){ }}

                        {{# }else{ }}
                            {{# if(d.is_send==0){ }}
                                {{# if(d.is_kaijiang==2){ }}
                                <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="edit">发货</a>
                                {{# } }}
                            {{# } }}

                            {{# if(d.is_send==1){ }}
                            <a class="layui-btn layui-btn-disabled layui-btn-xs" >已发货</a>
                            <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="code">查看发货单号</a>
                            {{# } }}

                        {{# } }}

                    </script>
                </div>
            </div>
        </div>
    </div>
</div>

<!--修改密码-->
<div id="editpassmodal"  style="display: none;padding:20px;">
    <form class="layui-form" action="" lay-filter="component-form-group">
        <div class="layui-form-item">
            <label class="layui-form-label">发货单号</label>
            <div class="layui-input-block">
                <input type="text" name="content"  id="editMinganContent" class="layui-input">
                <input type="hidden" name="id"  id="editMianganid">
            </div>
        </div>


        <div class="layui-form-item layui-layout-admin">
            <div class="layui-input-block">
                <div class="layui-inline" style="left: 0;">
                    <button class="layui-btn layui-btn-normal" lay-submit="" lay-filter="editmingansubmit">立即提交</button>
                </div>
            </div>
        </div>
    </form>
</div>


<!--修改密码-->
<div id="passmodal"  style="display: none;padding:20px;">
    <form class="layui-form" action="" lay-filter="component-form-group">
        <p style="text-align: center;margin-bottom: 20px">发货单号如需要修改，请修改完点击提交按钮</p>
        <div class="layui-form-item">
            <label class="layui-form-label">发货单号</label>
            <div class="layui-input-block">
                <input type="text" name="code"  id="code" class="layui-input">
                <input type="hidden" name="id"  id="id">
            </div>
        </div>


        <div class="layui-form-item layui-layout-admin">
            <div class="layui-input-block">
                <div class="layui-inline" style="left: 0;">
                    <button class="layui-btn layui-btn-normal" lay-submit="" lay-filter="submits">提交</button>
                </div>
            </div>
        </div>
    </form>
</div>
<script src="/static/layuiadmin/layui/layui.js"></script>
<script>
    layui.config({
        base: '/static/layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index','form','table','laydate','set'], function(){
        $ = layui.jquery;
        var table = layui.table
            ,admin = layui.admin
            ,element = layui.element
            ,layer = layui.layer
            ,laydate = layui.laydate
            ,form = layui.form;

        table.render({
            elem: '#test-table-operate'
            ,url: "{:url('Jlou/order')}"
            ,height: 'full-155'
            ,cols: [[
                {field:'order_id',width:80,align:"center",  title: '订单ID'}
                ,{field:'order_sn',align:"center",title: '订单编号'}
                ,{field:'order_code',align:"center",title: '订单参与码'}
                ,{field:'date',align:"center",title: '哪一期商品'}
                ,{field:'name',align:"center",title: '姓名'}
                ,{field:'address',align:"center",title: '地址'}
                ,{field:'phone',align:"center",title: '手机号'}
                ,{field:'order_price',align:"center",title: '订单价格'}
                ,{field:'order_status',align:"center",title: '是否支付',templet:function(d){
                        if (d.order_status == 1){
                            return "已支付";
                        }else if(d.order_status == 0){
                            return "未支付";
                        }
                    }}
                ,{field:'is_kaijiang',align:"center",title: '是否开奖',templet:function(d){
                        if (d.is_kaijiang == 0){
                            return "未到时间";
                        }else if(d.is_kaijiang == 1){
                            return "等待开奖";
                        }else if(d.is_kaijiang ==2){
                            return "已开奖";
                        }else if(d.is_kaijiang ==3){
                            return "人数不足";
                        }
                    }}
                ,{field:'is_have',align:"center",title: '是否中奖',templet:function(d){
                        if (d.is_have == 1){
                            return "<span style='color: red'>中奖</span>";
                        }else if(d.is_have == 0){
                            return "未中奖";
                        }
                    }}
                ,{align:'center',width:200, title: '操作',fixed: 'right', toolbar: '#test-table-operate-barDemo'}
            ]]
            ,page: true
            ,limit: 20
        });

        form.render(null, 'component-form-group');

        laydate.render({
            elem: '#LAY-component-form-group-date'
        });

        //监听工具条
        table.on('tool(test-table-operate)', function(obj){
            var data = obj.data;
            if(obj.event === 'edit'){
                $('#editMianganid').val(data.order_id);
                var editpassmodal = layer.open({
                    title:'快递单号'
                    ,type: 1

                    ,shadeClose: true
                    ,area: admin.screen() < 2 ? ['60%'] : ['500px']

                    ,content: $('#editpassmodal')
                });

            } else if(obj.event ==="code"){
                $('#code').val(data.dk_code);
                $('#id').val(data.order_id);
                var editpassmodal = layer.open({
                    title:'查看修改快递单号'
                    ,type: 1

                    ,shadeClose: true
                    ,area: admin.screen() < 2 ? ['60%'] : ['500px']

                    ,content: $('#passmodal')
                });
            }
        });

        //添加提交
        form.on('submit(addsubmit)', function(data){
            var loading = layer.load(1, {
                shade: [0.1,'#fff'] //0.1透明度的白色背景
            });
            $.ajax({
                url: "{:url('Comment/add')}",
                type: 'post',
                dataType: 'json',
                data: {data:data.field},
                success: function(data){
                    if (data.code === 0) {
                        layer.msg('添加成功',{icon:1,time:2000},function(){
                            window.location.reload();
                        });
                    }else{
                        layer.close(loading);
                        layer.msg(data.code,{icon:2,time:1000})
                    }
                }
            })
            return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
        });
        //修改敏感字
        form.on('submit(editmingansubmit)', function(data){
            var loading = layer.load(1, {
                shade: [0.1,'#fff'] //0.1透明度的白色背景
            });
            $.ajax({
                url: "{:url('Jlou/send_code')}",
                type: 'post',
                dataType: 'json',
                data: {data:data.field},
                success: function(info){
                    if (info.code === 0) {
                        layer.msg('添加成功',{icon:1,time:2000},function(){
                            window.location.reload();
                        });
                    }else{
                        layer.close(loading);
                        layer.msg(info.code,{icon:2,time:1000})
                    }

                }
            })
            return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
        });


        //确认密码
        form.on('submit(submits)', function(data){
            var loading = layer.load(1, {
                shade: [0.1,'#fff'] //0.1透明度的白色背景
            });
            $.ajax({
                url: "{:url('Jlou/edit_code')}",
                type: 'post',
                dataType: 'json',
                data: {data:data.field},
                success: function(info){
                    if (info.code === 0) {
                        layer.msg('修改成功',{icon:1,time:2000},function(){
                            window.location.reload();
                        });
                    }else{
                        layer.close(loading);
                        layer.msg(info.code,{icon:2,time:1000})
                    }

                }
            })
            return false;
        });
        var $ = layui.$, active = {
            searchUserButton:function(){
                var order_sn  = $('#order_sn').val();
                var date  = $('#date').val();
                var is_kaijiang = $("#is_kaijiang").val();
                var order_status = $("#order_status").val();
                table.reload('test-table-operate', {
                    where: {
                        order_sn: order_sn,
                        date:date,
                        is_kaijiang:is_kaijiang,
                        order_status:order_status
                    }
                    ,page: {
                        curr: 1 //重新从第 1 页开始
                    }
                });
                //return false;
            },
            addadmin: function() {
                window.location.href="{:url('Jlou/addGoods')}";
            }
        };
        //绑定点击事件
        $('.test-table-operate-btn .layui-btn').on('click', function(){
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });


    });



</script>


</body>
</html>